define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'zong_price', title: __('Zong_price'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'fangjian_id', title: __('Fangjian_id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('退款订单')}, formatter: Table.api.formatter.status},
                        {field: 'is_write_off', title: __('is_write_off'), searchList: {"0":__('is_write_off 0'),"1":__('is_write_off 1')}, formatter: Table.api.formatter.status},
                        {field: 'fuwu', title: __('Fuwu'), operate: 'LIKE'},
                        {field: 'fuwu_sc', title: __('Fuwu_sc'), operate: 'LIKE'},
                        {field: 'j_time', title: __('服务结束时间')},

                        // {field: 'taocan', title: __('Taocan'), operate: 'LIKE'},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'x_id', title: __('X_id')},
                        // {field: 'x_status', title: __('X_status')},
                         {field: 'x_status', title: __('X_status'), searchList: {"0":__('正常订单'),"1":__('续费订单'),"2":__('商家代下单')}, formatter: Table.api.formatter.status},

                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'fangjian.name', title: __('Fangjian.name'), operate: 'LIKE'},
						{field: 'pay_type', title: __('支付方式'), searchList: {0:__('未知'),1:__('微信'),2:__('余额')}, formatter: Table.api.formatter.status},
                        {field: 'is_send_settlement_money', title: __('是否结算'), searchList: {0:__('未结算'),1:__('已结算'),2:__('无需结算')}, formatter: Table.api.formatter.status},
                        {field: 'profit_sharing_status', title: __('分账'), searchList: {0:__('未分账'),1:__('已分账')}, formatter: Table.api.formatter.status},
                        {field: 'settlement_money', title: __('实际结算订单金额')},
                        {field: 'settlement_amount', title: __('商家结算金额')},
                        {field: 'refund_money', title: __('退款金额')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [{
                                name: 'share',
                                title: '分账',
                                text: '分账',
                                classname: 'btn btn-xs btn-info btn-ajax',
                                url: 'order/share/id/{ids}',
                                confirm: '是否确认分账？',
                                refresh: true,
                                hidden: function(row){
                                    return row.profit_sharing_status==1;
                                },
                            }],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
